package miao.byusi.bkata.logs

/**
 * 控制台渲染器
 */
class ConsoleRenderer(private val theme: Theme = Theme()) {
    private val resetCode = "\u001B[0m"
    
    fun render(level: LogLevel, message: String): String {
        val style = theme.getStyle(level)
        val ansiCodes = style.toAnsiCodes()
        
        return if (ansiCodes.isNotEmpty()) {
            "\u001B[${ansiCodes}m$message$resetCode"
        } else {
            message
        }
    }
    
    fun renderWithPrefix(level: LogLevel, prefix: String, message: String): String {
        val style = theme.getStyle(level)
        val ansiCodes = style.toAnsiCodes()
        val levelName = level.name.lowercase().replaceFirstChar { it.uppercase() }
        
        return if (ansiCodes.isNotEmpty()) {
            "\u001B[${ansiCodes}m$prefix [$levelName] $message$resetCode"
        } else {
            "$prefix [$levelName] $message"
        }
    }
}